﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class admin_Admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (UserName.Text == "")
        { Response.Write("<script >function window.onload() {alert('帐号不能为空!');}</script>"); return; }
        else if (PassWord.Text == "")
        { Response.Write("<script >function window.onload() {alert('密码不能为空!');}</script>"); return;}
        else if (ImgCode.Text =="")
        { Response.Write("<script >function window.onload() {alert('验证码不能为空!');}</script>"); return; }
        else if (Server.HtmlEncode(ImgCode.Text.ToString().Trim().ToLower()) != Session["CheckCode"].ToString().ToLower())
        { Response.Write("<script >function window.onload() {alert('验证码不正确!');}</script>"); return; }
        else
        { 

        Admin admins = new Admin();
        OleDbDataReader dr = admins.CheckAdmin(Server.HtmlEncode(UserName.Text.Trim()),DB.Encrypt(Server.HtmlEncode(PassWord.Text.Trim())));

        if (dr.Read())
        {
            string user = Server.HtmlEncode(UserName.Text.Trim());
            string pwd = DB.Encrypt(Server.HtmlEncode(PassWord.Text.Trim()));
            HttpCookie myCookie = new HttpCookie("adminCack");
            myCookie.Values.Add("Username", user);
            myCookie.Values.Add("Pwd", pwd);
            myCookie.Expires = DateTime.Now.AddDays(1);
            Response.AppendCookie(myCookie);

            //Session["AdminId"] = dr["Aid"].ToString();
            Response.Redirect("Admin_Default.aspx");
            Session.Remove("CheckCode");
        }
        else
        {
            Response.Write("<script >function window.onload() {alert('帐号或密码不正确!');}</script>");
        }
        }
    }
}
